﻿using System;
using System.Web;

namespace BLWCMS.Core.Helpers
{
    public class HttpHelper
    {
        #region 获得当前客户端的IP
        /// <summary>
        /// 获得当前客户端的IP
        /// </summary>
        /// <returns>当前页面客户端的IP</returns>
        public static string GetGuestIp()
        {
            string result = String.Empty;

            result = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
            if (string.IsNullOrEmpty(result))
            {
                result = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
            }
            if (string.IsNullOrEmpty(result))
            {
                result = HttpContext.Current.Request.UserHostAddress;
            }
            if (string.IsNullOrEmpty(result))
            {
                return "127.0.0.1";
            }
            return result;
        } 
        #endregion
    }
}
